package ai.graph;

import edu.uci.ics.jung.graph.ArchetypeEdge;
import edu.uci.ics.jung.graph.ArchetypeVertex;
import edu.uci.ics.jung.graph.decorators.EdgeStringer;
import edu.uci.ics.jung.graph.decorators.VertexStringer;
import edu.uci.ics.jung.visualization.PluggableRenderer;

public class MyRenderer extends PluggableRenderer {

	public MyRenderer() {
		super();
		setVertexStringer(new VertexStringer() {

			public String getLabel(ArchetypeVertex v) {
				return get(v, GraphConstants.TYPE)+"["+get(v, GraphConstants.NAME)+"]";
			}
			
			private String get(ArchetypeVertex v, String key) {
				if(v.getUserDatum(key)!=null) {
					return v.getUserDatum(key).toString();
				}
				return "";
			}
			
			
			
		});
		
		setEdgeStringer(new EdgeStringer() {

			public String getLabel(ArchetypeEdge e) {
				if (e instanceof NamedRelation) {
					NamedRelation rel = (NamedRelation) e;
					return rel.getName();
				}
				return null;
			}
			
		});
	}

}
